<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    /* 
      https://leetcode-cn.com/problems/kth-largest-element-in-an-array/
      思路：https://leetcode-cn.com/problems/kth-largest-element-in-an-array/solution/javascriptsi-chong-fang-shi-jie-topkwen-ti-by-user/
    */
    let nums = [3,2,3,1,2,4,5,5,6];
    let k = 4;

    function findKthLargest(nums, k) {
      // 方法1、数组排序，取第 k 个数，最简单.
      nums.sort((a, b) => b - a);
      return nums[k-1];
    }
    console.log(findKthLargest(nums, k)); // 4
  </script>
</body>
</html>